﻿using System;
using System.Linq;

namespace PlottingBasics.Axis
{
    /// <summary>
    /// Simple base class to make generating an axis easy
    /// </summary>
    public abstract class AxisFunctorBase : IAxis
    {
        private int _bins;

        /// <summary>
        /// Init the helper funct with a func that will return a new func that will
        /// walk the iterator through
        /// </summary>
        /// <param name="calc"></param>
        /// <param name="bins"></param>
        public AxisFunctorBase(int bins)
        {
            _bins = bins;
        }

        /// <summary>
        /// Override to give the simple iterator function.
        /// </summary>
        /// <returns></returns>
        protected abstract Func<double> getIteratorFunc();

        /// <summary>
        /// iterates through the values.
        /// </summary>
        /// <returns></returns>
        public System.Collections.Generic.IEnumerator<double> GetEnumerator()
        {
            Func<double> doCalc = getIteratorFunc();
            foreach (var i in Enumerable.Range(0, _bins+1))
            {
                yield return doCalc();
            }
        }

        #region IEnumerable Members

        System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
        {
            throw new NotImplementedException();
        }

        #endregion
    }
}
